package com.ysh.aop.advice;

import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;

/**
 * 袁胜虎 on 2022/8/27 20:21
 */
//MethodBeforeAdvice 前置通知  AfterReturningAdvice 后置通知
public class TranAdvice implements MethodBeforeAdvice, AfterReturningAdvice {
    /**
     * 在我们的目标方法执行之前先执行,相当于我们web中filter在放行之前的代码
     * @param method
     * @param args
     * @param target
     * @throws Throwable
     */
    @Override
    public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
        System.err.println("提交事务");
        System.err.println("原先返回的值是:"+returnValue);
    }

    @Override
    public void before(Method method, Object[] args, Object target) throws Throwable {
        System.err.println("开启事务了");
    }
}
